package beans;

import java.io.IOException;
import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.primefaces.context.RequestContext;
import org.primefaces.event.FileUploadEvent;

import util.HibernateUtil;
import controlador.Principal;

public class Operaciones implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Operaciones() {
		super();
	}

	public void cargaPagPreguntas(ActionEvent actionEvent) {
		try {
			FacesContext
					.getCurrentInstance()
					.getExternalContext()
					.redirect(
							"/Sistema_Evaluacion_Aprendizaje/faces/carga_preguntas.xhtml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void cargaBanco(ActionEvent actionEvent) {
		try {
			FacesContext
					.getCurrentInstance()
					.getExternalContext()
					.redirect(
							"/Sistema_Evaluacion_Aprendizaje/faces/banco_preg.xhtml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void save(ActionEvent actionEvent) {
		RequestContext context = RequestContext.getCurrentInstance();
		FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
				"Pregunta Cargada", "Cod: T000121");
		;
		boolean loggedIn = true;

		FacesContext.getCurrentInstance().addMessage(null, msg);
		context.addCallbackParam("loggedIn", loggedIn);
	}

	public void aprobarPreguntas(ActionEvent actionEvent) {
		if (Principal.getCp_coordinador().getCurso() != null) {
			try {
				System.out.println(" ES COORDINADOR!!!!");
				FacesContext
						.getCurrentInstance()
						.getExternalContext()
						.redirect(
								"/Sistema_Evaluacion_Aprendizaje/faces/cc_aprobarpreg.xhtml");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			System.out.println("NO ES COORDINADOR!!!!");
			FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
					"No es coordinador", "No es coordinador de algun curso");
			;
			FacesContext.getCurrentInstance().addMessage(null, msg);
		}
	}	
	
	public void salir(ActionEvent actionEvent) {
		try {
			Principal.CerrarSesion();
			Principal.CerrarSesion();
			FacesContext
					.getCurrentInstance()
					.getExternalContext()
					.redirect(
							"/Sistema_Evaluacion_Aprendizaje/faces/login.xhtml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
